<template>
  <div class="ele-body">
    <!-- 搜索表单 -->
    <div class="block-interval">
      <a-card :bordered="false">
        <a-form layout="inline" :model="where">
          <a-row>
            <a-form-item label="开始时间:">
              <a-date-picker v-model:value="where.searchBeginTime" type="date" show-time format="YYYY-MM-DD HH:mm:ss" valueFormat="YYYY-MM-DD HH:mm:ss" />
            </a-form-item>
            <a-form-item label="结束时间:">
              <a-date-picker v-model:value="where.searchEndTime" type="date" show-time format="YYYY-MM-DD HH:mm:ss" valueFormat="YYYY-MM-DD HH:mm:ss" />
            </a-form-item>
            <a-form-item class="ele-text-center">
              <a-space>
                <a-button type="primary" @click="reload">查询</a-button>
                <a-button @click="reset">重置</a-button>
              </a-space>
            </a-form-item>

          </a-row>
        </a-form>
      </a-card>
    </div>

    <!-- 表格 -->
    <div>
      <a-card :bordered="false">
        <ele-pro-table
          ref="table"
          row-key="dlsdId"
          :datasource="datasource"
          :columns="columns"
          :where="where"
          v-model:selection="selection"
          :scroll="{ x: 'max-content' }"
        >

          <template #bodyCell="{ column, record }">
            <!-- table操作栏按钮 -->
            <template v-if="column.key === 'action'">
              <a-space>
                <a @click="openDetail(record)">详情</a>
                <a-divider type="vertical" />
                <a-popconfirm title="确定要删除此记录吗？" @confirm="remove(record)">
                  <a class="ele-text-danger">删除</a>
                </a-popconfirm>
              </a-space>
            </template>
          </template>
        </ele-pro-table>
      </a-card>
    </div>
  </div>

  <!-- 编辑弹窗 -->
  <DeviceLuoxunSimplephaseDataDetail v-if="showDetail" v-model:visible="showDetail" :data="current"/>
</template>

<script>
import { DeviceLuoxunSimplephaseDataApi } from '@/api/property/DeviceLuoxunSimplephaseDataApi';
import  DeviceLuoxunSimplephaseDataDetail from './luoxunsimplephase-data-detail.vue';
import { message } from 'ant-design-vue';

export default {
  name: 'DeviceLuoxunSimplephaseData',
  components: {
    DeviceLuoxunSimplephaseDataDetail
  },
  async mounted() {
  },
  props: {
    data: Object
  },
  data() {
    return {
      // 表格列配置
      columns: [
        {
          title: '上报时间',
          dataIndex: 'uploadTime'
        },
        {
          title: '信号量',
          dataIndex: 'signalValue'
        },
        {
          title: '电池电压(V)',
          dataIndex: 'elePress'
        },
        {
          title: '电源电压(V)',
          dataIndex: 'secElePress'
        },
        {
          title: '电压(V)',
          dataIndex: 'sensorVoltage'
        },
        {
          title: '电流(A)',
          dataIndex: 'sensorCurrent'
        },
        {
          title: '有功功率(W)',
          dataIndex: 'activitypower'
        },
        {
          title: '漏电流(mA)',
          dataIndex: 'leakageCurrent'
        },
        {
          title: '火线温度量(℃)',
          dataIndex: 'fireTemperature'
        },
        {
          title: '零线温度量(℃)',
          dataIndex: 'zeroTemperature'
        },
        {
          title: '操作',
          key: 'action',
          align: 'center'
        }
      ],
      // 表格搜索条件
      where: {"recordId" : this.data.recordId},
      // 表格选中数据
      selection: [],
      // 当前编辑数据
      current: null,
      // 是否显示编辑弹窗
      showEdit: false,
      showDetail : false
    };
  },
  methods: {
    /**
     * 搜索按钮
     *
     * @author cancan
     * @date 2022/10/04 15:24
     */
    reload() {
      this.selection = [];
      this.$refs.table.reload({ page: 1 });
    },

    /**
     * 重置搜索
     *
     * @author cancan
     * @date 2022/10/04 15:24
     */
    reset() {
      this.where.recordId = this.data.recordId;
      this.where.searchBeginTime = '';
      this.where.searchEndTime = '';
      this.$nextTick(() => {
        this.reload();
      });
    },

    /**
     * 删除
     *
     * @author cancan
     * @date 2022/10/04 15:24
     */
    async remove(row) {
      const result = await DeviceLuoxunSimplephaseDataApi.delete({ dlsdId: row.dlsdId });
      message.success(result.message);
      this.reload();
    },

    /**
     * 打开新增或编辑弹窗
     *
     * @author cancan
     * @date 2022/10/04 15:24
     */
    openEdit(row) {
      this.current = row;
      this.showEdit = true;
    },
    /**
     * 获取表格数据
     *
     * @author fengshuonan
     * @date 2022/5/8 15:18
     */
    datasource({ page, limit, where, orders }) {
      return DeviceLuoxunSimplephaseDataApi.findPage({ ...where, ...orders, pageNo: page, pageSize: limit });
    },

    /**
     * 打开新增或编辑弹窗
     *
     * @author cancan
     * @date 2022/03/05 14:48
     */
    openDetail(row) {
      this.current = row;
      this.showDetail = true;
    },
  }
};
</script>
